#include "fCanvasManager.h"
#include "fFramework.h"
#include "fCtlCanvas.h"
#include "fWindow.h"
fCanvasManager::fCanvasManager( fWidget* aFramework )
{
    iFramework = aFramework;
}

fCanvasManager::~fCanvasManager()
{

}

fTopmost* fCanvasManager::GetTopMostCtl()
{
    /*
    if ( iCurrentCanvas->iMenuBar && iCurrentCanvas->iMenuBar->CurrentState() != VIVACtlMenuBar::KMenuHide)
    {
        return  iCurrentCanvas->iMenuBar;
    }

    RPointerArray< fDialog >& topmosts = iCurrentCanvas->TopMost();
    int count = topmosts.Count();
    fDialog* topTemp = NULL;
    for ( int index = 0; index < count; index++ )
    {
        topTemp = topmosts[index];
        if ( topTemp->_visible )
        {
            return topTemp;
        }
    }
    */
    return NULL;
}

fCanvas* fCanvasManager::GetCurrentCtl()
{
    return iCurrentCanvas;
}

void fCanvasManager::ChangeCanvas( int aCanvasIndex, const TDesC& aCommandline, void* data )
{
    fCanvas* prevCanvas = iCurrentCanvas;
    if ( prevCanvas )
    {
        prevCanvas->SwitchFromCanvas();
    }

    DoChangeCanvas( aCanvasIndex, aCommandline, data );

    if( iCurrentCanvas )
    {
        if ( prevCanvas != iCurrentCanvas )
        {
            iCurrentCanvas->PrevCanvas( prevCanvas );
        }

        iCurrentCanvas->SwitchToCanvas( aCommandline, data );
    }
}

void fCanvasManager::DoChangeCanvas( int aCanvasIndex, const TDesC& aCommandline, void* _data )
{
    _ASSERT_LOG( 0 );
}

void fCanvasManager::DeleteCanvas( fCanvas*canvas )
{
    _ASSERT_LOG( 0 );
}

void fCanvasManager::GoBackCanvas()
{
    if ( iCurrentCanvas )
    {
        if ( iCurrentCanvas->PrevCanvas() )
        {
            iCurrentCanvas->SwitchFromCanvas();
            fCanvas* prevViewCanvas = iCurrentCanvas->PrevCanvas( );
            DeleteCanvas( iCurrentCanvas );
            iCurrentCanvas = prevViewCanvas;
            iCurrentCanvas->SwitchBack();
        }
        else
        {
            iCurrentCanvas->SwitchFromCanvas();
            DoExit();
        }
    }
    else
    {
        _ASSERT_LOG( 0 );
    }
}
